
<%@ page import="auctionhaus.Listing"%>
<!doctype html>
<html>
<head>
<meta name="layout" content="main">
<g:set var="entityName"
	value="${message(code: 'listing.label', default: 'Listing')}" />
<g:set var="customerName"
	value="${message(code: 'customer.label', default: 'Customer')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
	<a href="#list-listing" class="skip" tabindex="-1"><g:message
			code="default.link.skip.label" default="Skip to content&hellip;" /></a>
	<div class="nav" role="navigation">
		<ul>
			<li><a class="home" href="${createLink(uri: '/')}"><g:message
						code="default.home.label" /></a></li>
			<li><g:link class="create" action="create">
					<g:message code="default.new.label" args="[entityName]" />
				</g:link></li>

			<li><g:link controller="customer" class="list" action="list">
					<g:message code="default.list.label" args="[customerName]" />
				</g:link></li>

			<li><g:link controller="customer" class="create" action="create">
					<g:message code="default.new.label" args="[customerName]" />
				</g:link></li>
		</ul>
	</div>
	<div id="list-listing" class="content scaffold-list" role="main">
		<h1>
			<g:message code="listings.label" args="[entityName]" />
		</h1>
		<g:if test="${flash.message}">
			<div class="message" role="status">
				${flash.message}
			</div>
		</g:if>
		<table>
			<thead>
				<tr>
					<!-- M-5: The name is visible for each listing -->
					<th>
						${message(code: 'listing.name.label', default: 'Name')}
					</th>

					<th><g:message code="listing.seller.label" default="Seller" /></th>


					<!--g:sortableColumn property="description"
						title="${message(code: 'listing.description.label', default: 'Description')}" /-->

					<!-- M-6: The number of bids is visible for each listing -->
					<th>
						${message(code: 'listing.numberOfBids.label', default: 'Number of Bids')}
					</th>

					<!-- M-7: The starting price is visible for each listing -->
					<!-- M-9: Listings can be sorted by starting price -->
					<g:sortableColumn property="startingPrice"
						title="${message(code: 'listing.starting.price.label', default: 'Starting Price')}" />

						
					<th><g:message code="listing.high.bid.label" default="High Bid" /></th>
					<th><g:message code="listing.high.bidder.label" default="High Bidder" /></th>

					<!-- M-8: The end date/time is visible for each listing -->
					<!-- M-10: Listings can be sorted by end date/time -->
					<g:sortableColumn property="endDateTime"
						title="${message(code: 'listing.endDateTime.label', default: 'End Date Time')}" />

					<!--th><g:message code="listing.winner.label" default="Winner" /></th-->



					<g:sortableColumn property="dateCreated"
						title="${message(code: 'listing.dateCreated.label', default: 'Date Created')}" />

				</tr>
			</thead>
			<tbody>
				<g:each in="${listingInstanceList}" status="i" var="listingInstance">
					<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

						<!-- M-11: A user can click on a listing to see additional details about that listing -->
						<td><g:link action="show" id="${listingInstance.id}">
								${fieldValue(bean: listingInstance, field: "name")}
							</g:link></td>
							
							<td><g:link action="show" controller="customer" id="${listingInstance.seller.id}">
								${fieldValue(bean: listingInstance, field: "seller")}
							</g:link></td>
							
						<!--td>
							${fieldValue(bean: listingInstance, field: "description")}
						</td-->

						<td>
							${listingInstance.bids.size()}
						</td>

						<!--td>
							${fieldValue(bean: listingInstance, field: "winner")}
						</td-->

						<td>$${fieldValue(bean: listingInstance, field:
							"startingPrice")}</td>
							
						<g:if test="${listingInstance.bids.size()!=0}">	
						<td>
						<g:link action="show" controller="bid" id="${listingInstance.bids.get(listingInstance.bids.size()-1).id}">
								${listingInstance.bids.get(listingInstance.bids.size()-1)}
							</g:link>
						</td>
						</g:if>
						<g:else>
						<td>
							${message(code: 'listing.no.bids.label', default: "No Bids.")}
						</td>
						</g:else>
						
						<g:if test="${listingInstance.bids.size()!=0}">	
						<td>
						<g:link action="show" controller="customer" id="${listingInstance.bids.get(listingInstance.bids.size()-1).bidder.id}">
								${listingInstance.bids.get(listingInstance.bids.size()-1).bidder}
							</g:link>
						</td>
						</g:if>
						<g:else>
						<td>
							${message(code: 'listing.no.bids.label', default: "No Bids.")}
						</td>
						</g:else>


						<td><g:formatDate date="${listingInstance.endDateTime}" /></td>


						<td><g:formatDate date="${listingInstance.dateCreated}" /></td>



					</tr>
				</g:each>
			</tbody>
		</table>
		<div class="pagination">
			<g:paginate total="${listingInstanceTotal}" />
		</div>
	</div>
</body>
</html>
